package helper;

import goods.Goods;
import order.Order;
import org.apache.commons.lang.StringUtils;
import play.Logger;
import utils.DateUtil;
import utils.Md5Utils;

/**
 * 农行支付
 */
public class SmartHelper {

//    public static final String NO = "999290053110222";
    public static final String KEY = "abcdefgh";
    public static final String MSG_PASSWORD = "abcdefgh";
    public static final String TRAN_CODE= "01";
    public static final String FORE_URL = "http://ulcweixin.ulmsale.net/weixin/userCenter";
    public static final String BACK_URL = "http://ulcweixin.ulmsale.net/order/smartPay/callBack";


    public static String paySign(Order order) {
        String tranCode = TRAN_CODE;
        String merchantId = "999290053110222";
        String orderNo = order.orderNumber;
        Double totalAmt = order.paymentedAmount * 100;
        Logger.info("totalAmt : %s" , totalAmt);
        String merTranDateTime = DateUtil.dateToString(order.createdAt , "yyyyMMddHHmmss");
        String currencyType = "156";
        String plain = "tranCode=" + tranCode+ "&merchantId=" + merchantId + "&merOrderNum="+orderNo
                + "&totalAmt=" + totalAmt.intValue()+ "&merTranDateTime=" + merTranDateTime+ "&backNeed=1&backUrl=" +BACK_URL+ "&reqKey=" +KEY;
        Logger.info("plain : %s" , plain);
        //加密串
        String signValue =  Md5Utils.signature(plain);
        return signValue;
    }
}
